package day_2022_9_to_12.Day;

import java.util.LinkedList;
import java.util.List;

/**
 * @author haomin
 * @date 2022/10/18 21:45
 **/
public class Day46_3_Num257_BinaryTreePaths {
    class Solution {
        List<String> res = new LinkedList<>();
        public List<String> binaryTreePaths(TreeNode root) {
            preOrd(root, "");
            return res;
        }
        private void preOrd(TreeNode root, String str){
            if(root == null) return;
            StringBuffer sb = new StringBuffer(str);
            sb.append(root.val);
            if(root.left == null && root.right == null){
                res.add(new String(sb));
            }else {
                sb.append("->");
                preOrd(root.left, sb.toString());
                preOrd(root.right, sb.toString());
            }
        }
    }
}